package com.ch;

import com.ch.domain.Student;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author chenhong
 * @version 1.0.0
 * @ClassName Test01.java
 * @Description TODO
 * @createTime 2020年12月21日 21:51:00
 */

//获取类的信息
public class Test01 {
    public static void main(String[] args) throws ClassNotFoundException {
        Class c1 = Class.forName("com.ch.domain.Student");
        System.out.println(c1.getName());
        System.out.println(c1.getSimpleName());
        //getFields()只能找到非私有属性
        System.out.println("getFields()只能找到非私有属性");
        Field []fields = c1.getFields();
        for(Field field :fields){
            System.out.println(field);
        }
        System.out.println("getDeclaredFields()只能找到本类的所有声明属性");
        Field []fields2 = c1.getDeclaredFields();
        for(Field field :fields2){
            System.out.println(field);
        }


        System.out.println("获取本类和父类的全部public方法");
        Method []methods = c1.getMethods();
        for(Method method:methods){
            System.out.println(method);
        }
        System.out.println("获取本类声明了的方法");
        Method []methods2 = c1.getDeclaredMethods();
        for(Method method:methods2){
            System.out.println(method);
        }
    }
}
